var city = "沧州";
function loadXMLDoc() {
	var xmlhttp;
	if (window.XMLHttpRequest) {
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp = new XMLHttpRequest();
	}
	else {
		// IE6, IE5 浏览器执行代码
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function () {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
			//搜索城市


			var json = JSON.parse(xmlhttp.responseText);
			console.log(json);
			
			var list = document.querySelectorAll("#list li");
			for (let i = 0; i < list.length; i++) {
				//console.log(list[i]);
				//日期
				list[i].children[1].innerHTML = json.daily_forecast[i].date.slice(5);
				//console.log(list[i].children[1]); 
				//阴、晴
				list[i].children[2].innerHTML = json.daily_forecast[i].cond.txt_d;
				//console.log(list[i].children[2]);
				//console.log(list[i].children[3].children[0]);
				//度数
				//console.log(list[i].children[3])
				list[i].children[3].children[0].innerHTML = json.daily_forecast[i].tmp.max;

				list[i].children[3].children[1].innerHTML = json.daily_forecast[i].tmp.min;

				//console.log(list[i].children[4].children[0]);
				//风
				list[i].children[4].children[0].innerHTML = json.daily_forecast[i].wind.dir;
				list[i].children[4].children[1].innerHTML = json.daily_forecast[i].wind.sc;


			}
			//小时
			var ll = document.querySelectorAll("#ll li");
			for (let j = 0; j < ll.length; j++) {
				console.log(ll[j]);
				ll[j].children[0].innerHTML = json.hourly_forecast[j].date.slice(10);
				//console.log(ll[j].children[0]);
				
				//度数
				ll[j].children[1].children[0].innerHTML = json.hourly_forecast[j].tmp;
				//console.log(ll[j].children[1].children[0])
			}








			//城市
			document.querySelector("#city").innerHTML = json.basic.city;
			document.querySelector("#du").innerHTML = json.now.fl;
			//多云
			document.querySelector("#duoyun").innerHTML = json.now.cond.txt;
			//33 优良
			document.querySelector("#liang").innerHTML = json.aqi.city.qlty;
			//风
			document.querySelector("#feng").innerHTML = json.now.wind.dir;
			document.querySelector("#ji").innerHTML = json.now.wind.sc;

			//气压
			document.querySelector("#qiya").innerHTML = json.now.pres;

			//建议
			document.querySelector("#tianqi").innerHTML = json.suggestion.sport.txt;
			//洗车
			document.querySelector("#xiche").innerHTML = json.suggestion.cw.txt;
			//运动
			document.querySelector("#yundong").innerHTML = json.suggestion.sport.txt;
			//防晒
			document.querySelector("#fangshai").innerHTML = json.suggestion.uv.txt;
			//感冒
			document.querySelector("#ganmao").innerHTML = json.suggestion.flu.txt;
			//穿衣
			document.querySelector("#chuanyi").innerHTML = json.suggestion.drsg.txt;
			//雨伞
			document.querySelector("#xiayu").innerHTML = json.suggestion.sport.txt;
		}


	}
	xmlhttp.open("GET", "https://bird.ioliu.cn/weather?city=" + city, true);
	xmlhttp.send();
}
loadXMLDoc();



document.querySelector("#ipt").addEventListener('change', function () {
	console.log(this.value);
	city = this.value;
	loadXMLDoc();
});


